package cn.fly.chatgpt.controller;

import cn.fly.chatgpt.domain.entity.Dialogue;
import cn.fly.chatgpt.service.ChatgptService;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class ChatgptController {


    @Resource
    private ChatgptService chatgptService;


    @GetMapping("/getDialogue/{chatId}")
    public AjaxResult  getDialogue(@RequestHeader(SecurityConstants.DETAILS_USER_ID) Integer userId, @PathVariable Long chatId) {
        System.out.println("userId => " + userId);
        Dialogue dialogue = chatgptService.getMyDialogue(userId, chatId);
        return AjaxResult.success(dialogue);
    }

    @GetMapping("/getChatList")
    public AjaxResult getChatList(@RequestHeader(SecurityConstants.DETAILS_USER_ID) Integer userId) {
        return AjaxResult.success(chatgptService.getChatList(userId));
    }

    @PostMapping("/newChat")
    public AjaxResult newChat(@RequestHeader(SecurityConstants.DETAILS_USER_ID) Integer userId) {
        chatgptService.newChat(userId);
        return AjaxResult.success();
    }
}
